import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Main from '../views/Main.vue'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: 'Home',
    component: Login
  },
  {
    path: '/index',
    name: 'index',
    component: Main
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to['path'] !== '/') {
   if (localStorage.getItem('login') === '1') {
     next()
   } else {
     // 未登录
     next({ path: '/' })
   }
  }

  next()
})

export default router
